//
//  RootViewController.m
//  FMDemoBaseMap
//
//  Created by fengmap on 16/10/17.
//  Copyright © 2016年 fengmap. All rights reserved.
//

#import "RootViewController.h"
#import "FMMapKit.h"

@interface RootViewController () <UITableViewDataSource, UITableViewDelegate>
{
    NSArray *_demoNameArray;
    NSArray *_viewControllerTitleArray;
    NSArray *_viewControllerArray;
}

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.title = [NSString stringWithFormat:@"Fengmap iOS SDK V%@ 地图显示", FMKGetMapSDKVersion()];
    
    _demoNameArray = @[
                       @"基础地图显示 - MapBasic",
                       @"地图初始化设置 - MapInitialize",
                       @"主题切换 - MapThemeSwitch",
                       @"地图操作(程序控制) - MapOperation",
                       @"楼层显示控制 - MapGroups",
                       @"图层显示控制 - MapLayers",
                       @"2D/3D切换 - Map2D3D",
                       @"坐标转换 - MapCoordTransfrom"
                       ];
    _viewControllerTitleArray = @[
                                  @"基础地图显示",
                                  @"地图初始化设置",
                                  @"主题切换",
                                  @"地图操作(程序控制)",
                                  @"楼层显示控制",
                                  @"图层显示控制",
                                  @"2D/3D切换",
                                  @"坐标转换"
                                  ];
    _viewControllerArray = @[
                             @"MapBasicDemoViewController",
                             @"MapInitializeDemoViewController",
                             @"MapThemeSwitchDemoViewController",
                             @"MapOperationDemoViewController",
                             @"MapGroupsDemoViewController",
                             @"MapLayersDemoViewController",
                             @"Map2D3DDemoViewController",
                             @"MapCoordTransfromDemoViewController"
                             ];

    [self.view addSubview:self.tableView];
    

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _demoNameArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"RootViewControllerCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.textLabel.text = _demoNameArray[indexPath.row];
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    UIViewController *viewController = [[NSClassFromString(_viewControllerArray[indexPath.row]) alloc] init];
    viewController.title = _viewControllerTitleArray[indexPath.row];
    
    UIBarButtonItem *customLeftBarButtonItem = [[UIBarButtonItem alloc] init];
    customLeftBarButtonItem.title = @"返回";
    self.navigationItem.backBarButtonItem = customLeftBarButtonItem;
    [self.navigationController pushViewController:viewController animated:YES];
}

#pragma mark - get
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.tableFooterView = [[UIView alloc] init];
    }
    return _tableView;
}

@end
